'use strict';
exports.main = async (event, context) => {
	const { tel } = event;
	
	const { data } = await uniCloud.database().collection('userList').where({ tel: tel }).get();
	
	if(data.length > 0) {
		const telCode = Math.random().toString(16).slice(2, 8);
		
		uniCloud.database().collection('userList').where({ tel: tel }).update({
			code: telCode
		})
			
		setTimeout(() => {
			uniCloud.database().collection('userList').where({ tel: tel }).update({
				code: null
			})
		}, 60 * 1000)
		
		return {
			code: 200,
			message: '获取验证码成功',
			data: {
				telCode: telCode
			}
		}
	} else {
		return {
			code: 400,
			message: '该手机号未注册'
		}
	}
};
